const Router = require('koa-router');
const db = require('../models/db');

const router = new Router();

// 数据库连接测试路由
router.get('/db-test', async (ctx) => {
  try {
    const result = await db.testConnection();
    if (result.success) {
      ctx.body = {
        status: 'success',
        message: '数据库连接正常',
        serverTime: result.time
      };
    } else {
      ctx.status = 500;
      ctx.body = {
        status: 'error',
        message: '数据库连接失败',
        error: result.error
      };
    }
  } catch (err) {
    ctx.status = 500;
    ctx.body = {
      status: 'error',
      message: '测试过程中发生错误',
      error: err.message
    };
  }
});

module.exports = router;